/*
 * ChatMcpConfig.java
 * Copyright 2025 Churan Tech, all rights reserved.
 * Churan PROPRIETARY/CONFIDENTIAL, any form of usage is subject to approval.
 */

package com.churan.ai.mcp.client.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.PromptChatMemoryAdvisor;
import org.springframework.ai.chat.memory.InMemoryChatMemoryRepository;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Function: mcp config
 *
 * @author churan
 * @date: 2025年5月7日
 */
@Configuration
public class ChatMcpConfig {

    @Bean
    public ChatClient chatClient(ChatClient.Builder chatClientBuilder, ToolCallbackProvider toolCallbackProvider) {
        final MessageWindowChatMemory chatMemory = MessageWindowChatMemory.builder().chatMemoryRepository(new InMemoryChatMemoryRepository()).build();
        return chatClientBuilder
                .defaultToolCallbacks(toolCallbackProvider.getToolCallbacks())
                .defaultAdvisors(PromptChatMemoryAdvisor.builder(chatMemory).build())
                .build();
    }
}
